package com.tf_cut.admin.seller.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.tf_cut.admin.annotation.Decrypt;
import com.tf_cut.admin.annotation.Encrypt;
import com.tf_cut.admin.backend.api.BackEndApi;
import com.tf_cut.admin.common.pojo.PageInfo;
import com.tf_cut.admin.common.pojo.Result;
import com.tf_cut.admin.seller.vo.ConfigSettingVo;
import com.tf_cut.admin.seller.vo.SellerAndAccountVo;

import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/sellerconfig/")
@Slf4j
public class SellerConfigController {
	
	@Autowired
	private BackEndApi sellerApi;
	
	// 进入商户服务类型配置页面
	@GetMapping("configlist")
    public ModelAndView sellerList() {
        return new ModelAndView("seller/config/list", "seller", null);
    }
	
	
	// 进入新增商户页面
	@GetMapping("configinsert")
    public ModelAndView sellerInsert() {
        return new ModelAndView("seller/config/configinsert", "seller", null);
    }
	
	@GetMapping(value = "findByName")
	public ModelAndView findByName(String id){
		ConfigSettingVo avo = null == id ? 
				new ConfigSettingVo() : 
					JSON.parseObject(sellerApi.findByName(id),ConfigSettingVo.class);
		return new ModelAndView("seller/config/configinsert", "config", avo);
	}
	
	@PostMapping(value = "deleteByName")
	public String deleteByName(String id){
		String result;
		result = sellerApi.deleteByName(id);
		return result;
	}
	
	@PostMapping(value = "save")
	public String save(ConfigSettingVo configSettingVo){
		String result;
		result = sellerApi.configSave(JSON.toJSONString(configSettingVo));
		return result;
	}
	
	
	
	// 商户服务类型配置页面查询分页
	@SuppressWarnings("unchecked")
	@PostMapping("configlist/page")
	@Decrypt
    @Encrypt
    public Result<PageInfo<ConfigSettingVo>> page(ConfigSettingVo avo) {
	
        String json = JSON.toJSONString(avo);
        json = sellerApi.findListConfigSeller(json);
        return Result.of(JSON.parseObject(json, PageInfo.class));
    }

}
